<style>
    .publish-config-box h3 {
        font-size: 16px;
        padding: 10px 10px;
        margin: 0;
        line-height: 1;
    }

    .config-table {
        background-color: #FFFFFF;
        font-size: 14px;
        padding: 15px 20px;
    }

    .config-table td {
        height: 35px;
        padding-left: 10px;
    }

    .config-input {
        width: 320px;
    }

    .info-box h3 {
        font-size: 15px;
        padding: 10px 10px;
        margin: 0;
        line-height: 1;
    }

    .feature {
        padding-top: 5px;
    }
</style>
<?php
$keydatas_password = '';
$keydatas_title_unique = false;
$keydatas_tbk_link_enble = false;
$formSubmit = sanitize_text_field($_POST['formSubmit']);
if (isset($formSubmit) && $formSubmit != '') {
    if (check_admin_referer('keydatas_save_nonce') && current_user_can('manage_options')) {
        $keydatas_password = sanitize_text_field($_POST['keydatas_password']);
        $kds_title_unique = sanitize_text_field($_POST['keydatas_title_unique']);
        $keydatas_title_unique = isset($kds_title_unique) && $kds_title_unique == "true";
        $kds_tbk_link_enble = sanitize_text_field($_POST['keydatas_tbk_link_enble']);
        $keydatas_tbk_link_enble = isset($kds_tbk_link_enble) && $kds_tbk_link_enble == "true";
        update_option('keydatas_password', $keydatas_password);
        update_option('keydatas_title_unique', $keydatas_title_unique);
        update_option('keydatas_tbk_link_enble', $keydatas_tbk_link_enble);
        echo '<div id="message" class="updated fade"><p>保存成功</p></div>';
    }
} else {
    $keydatas_password = get_option('keydatas_password', $keydatas_password);
    $keydatas_title_unique = get_option('keydatas_title_unique', $keydatas_title_unique);
    $keydatas_tbk_link_enble = get_option('keydatas_tbk_link_enble', $keydatas_tbk_link_enble);
}
?>
<div class="wrap">
    <h2>Api-Config</h2>
    <div style="margin-left:20px;padding-top:10px;padding-bottom:10px;">
    </div>
    <div class="publish-config-box">
        <h3>Setup</h3>
        <div>
            <form id="configForm" method="post" action="admin.php?page=api-config/publish-setting.php">
                <table width="100%" class="config-table">
                    <tr>
                        <td width="15%">Url:</td>
                        <td><input type="text" id="homeUrl" name="homeUrl" class="config-input" readonly value="<?php
                            if (isset($_SERVER["HTTPS"]) && strtolower($_SERVER["HTTPS"]) == "on") {
                                echo "https://";
                            } else {
                                echo "http://";
                            }
                            $domain = str_replace('\\', '/', $_SERVER['HTTP_HOST'] . str_replace('/wp-admin', '', dirname($_SERVER['SCRIPT_NAME'])));
                            echo $domain; ?>"/>

                        </td>
                    </tr>
                    <tr>
                        <td>Password:</td>
                        <td><input type="text" name="keydatas_password" class="config-input"
                                   value="<?php echo $keydatas_password; ?>"/>
                        </td>
                    </tr>
                    <tr>
                        <td>Pass if title exist:</td>
                        <td><input type="checkbox" name="keydatas_title_unique"
                                   value="true" <?php if ($keydatas_title_unique == true) echo "checked='checked'" ?> />If
                            post have the same title,pass it.
                        </td>
                    </tr>

                    <tr>
                        <td><input type="submit" name="formSubmit" value="Save" class="button-primary"/></td>
                        <td></td>
                    </tr>
                </table>
                <?php
                wp_nonce_field('keydatas_save_nonce');
                ?>
            </form>
        </div>
    </div>

</div>
